//
//  WJTopicVoiceView.m
//  BeDeJie
//
//  Created by jerry on 2017/2/2.
//  Copyright © 2017年 jerry. All rights reserved.
//

#import "WJTopicVoiceView.h"
#import <UIImageView+WebCache.h>
#import <AFNetworking.h>
#import "WJSeeBigPictureViewController.h"

@interface WJTopicVoiceView()

@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UILabel *palyCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *voiceTimeLabel;

@end

@implementation WJTopicVoiceView

- (void)awakeFromNib{
    [super awakeFromNib];
    
    //取消Autoresizing
    self.autoresizingMask = UIViewAutoresizingNone;
    //背景图片可以与用户交互
    self.bgImageView.userInteractionEnabled = YES;
    //背景图片设置点击后打开查看大图页面
    [self.bgImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seeBigPicture)]];
}

// 查看大图
- (void)seeBigPicture {
    WJSeeBigPictureViewController *seeBigPictureViewController = [[WJSeeBigPictureViewController alloc] init];
    seeBigPictureViewController.topic = self.topic;
    
    //第一种获取根控制器的方式
    [self.window.rootViewController presentViewController:seeBigPictureViewController animated:YES completion:nil];
    //第二种获取根控制器的方式
    //    [UIApplication sharedApplication].keyWindow.rootViewController;
}

- (void)setTopic:(WJTopic *)topic{
    _topic = topic;
    
    // 设置图片
    [self.bgImageView setOriginImage:topic.image1 thumbnailImage:topic.image0 placeholder:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL){
        WJLog(@"图片加载完成");
    }];
    // 播放数量
    if (topic.playcount >= 10000) {
        self.palyCountLabel.text = [NSString stringWithFormat:@"%.1f万播放", topic.playcount / 10000.0];
    } else {
        self.palyCountLabel.text = [NSString stringWithFormat:@"%zd播放", topic.playcount];
    }
    // %04d : 占据4位，多余的空位用0填补
    self.voiceTimeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd", topic.voicetime / 60, topic.voicetime % 60];
}

@end
